package com.appspot.aliga.presentation;

import java.util.List;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.appspot.aliga.LeagueTableEntry;
import com.appspot.aliga.R;
import com.appspot.aliga.service.ALigaService;

public class LeagueTableView extends AligaMainView {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.leaguetable_view);
		super.onCreate(savedInstanceState);		

		ALigaService service = new ALigaService(this);
		List<LeagueTableEntry> list = service.getLeagueTable(this.getCurrentLeague().getId());

		 setListAdapter(new LeagueTableEntryAdapter(this,list));


		ListView lv = getListView();
		lv.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				
				// When clicked, show a toast with the TextView text
				Toast.makeText(getApplicationContext(),
						((TextView) view).getText(), Toast.LENGTH_SHORT).show();
			}
		});	
	}
}